package com.yykj.hospital.server.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yykj.common.enums.ResultEnums;
import com.yykj.common.exception.NormalException;
import com.yykj.hospital.client.dto.HospitalDTO;
import com.yykj.hospital.client.form.HospitalEditForm;
import com.yykj.hospital.server.service.HospitalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/hospital")
@Api(tags = "医院信息相关")
@Slf4j
public class HospitalController {
    @GetMapping("/info/{id}")
    @ApiOperation(value = "医院信息")
    public HospitalDTO info(@PathVariable(name = "id") Integer id) {
        return hospitalService.getHospitalInfo(id);
    }

    @PutMapping("/info/edit")
    @ApiOperation(value = "医院修改")
    @ApiOperationSupport(ignoreParameters = {"name"})
    public HospitalDTO editHospital(
            @RequestBody HospitalEditForm hospitalEditForm) {
        if(hospitalEditForm.getId() == null || hospitalEditForm.getId()<0){
            throw new NormalException(ResultEnums.PARAM_ERROR);
        }
        return hospitalService.editHospital(hospitalEditForm);
    }

    private HospitalService hospitalService;

    @Autowired
    public void setHospitalService(HospitalService hospitalService) {
        this.hospitalService = hospitalService;
    }
}
